<template>
	<view>
		<view v-if="city">地址是：{{city}}</view>
		<view v-else>我还没有地址，去需要地址页</view>
		<button type="default" @click="changePage">去修改地址页</button>
		<button type="default" @click="clickoff">结束监听=>点击此按钮或返回上一页(页面卸载结束监听)</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			city: '',
		};
	},
	onUnload(){
		console.log('页面卸载,结束监听');
		uni.$off('changeAddress', this.changeAddress)
	},
	methods: {
		changeAddress(e){
				this.city = e.msg
		},
		changePage(){
			uni.$on('changeAddress', this.changeAddress);
			uni.navigateTo({
				url:'/pages/my/my-address-change'
			})
		},
		clickoff(){
			uni.$off('changeAddress', this.changeAddress)
		}
	}
};
</script>

<style></style>
